/**
 * Created by Administrator on 2017/4/23 0023.
 */
//跳转方法
function hrefgo(){
    //清除转发者信息 防止返回信息保存
    $.cookie("shareUserId","");
    $.cookie("fromuser","");
    //取消事件冒泡
    var e=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容
    if (e && e.stopPropagation) {
        // this code is for Mozilla and Opera
        e.stopPropagation();
    } else if (window.event) {
        // this code is for IE
        window.event.cancelBubble = true;
    }
    console.log(e.target.nodeName);
    console.log(e.target.className);
    if(e.target.nodeName==="DIV"){
        var url,pageid,euserid,eid;
        if(e.target.className==="feed_item feed_type_question"){
            console.log("1");
            url= e.target.parentNode.dataset.href;
            pageid=e.target.parentNode.dataset.page;
            euserid=e.target.parentNode.dataset.euser;
            eid=url.match(/[0-9]+/)[0];
        }else if(e.target.dataset.href){
            console.log("2");
            url= e.target.dataset.href;
            pageid=e.target.dataset.page;
            euserid=e.target.dataset.euser;
            eid=url.match(/[0-9]+/)[0];
        }
        $.cookie("pulupagescroll",$(window).scrollTop());//当前滚动距离
        $.cookie("pulupagepage",pageid);//当前显示页面
        $.cookie("quecurrentIndex",quecurrentIndex);//问题 铺路数据页码
        if(e.target.dataset.shareuserid){
            //shareuser="&shareuser="+e.dataset.shareuserid;
            $.cookie("shareUserId",e.target.dataset.shareuserid);
        }

        if(url&&url!="undefined"){
            //console.log(url);
            //console.log("跳转");
            location.href=url;
        }
    }
    //回答按钮
    else if(e.target.nodeName==="A"){
        if(e.target.dataset.href){
            var pageid=e.target.dataset.page;
            $.cookie("pulupagescroll",$(window).scrollTop());//当前滚动距离
            $.cookie("pulupagepage",pageid);//当前显示页面
            $.cookie("quecurrentIndex",quecurrentIndex);//问题 铺路数据页码
            var url= e.target.dataset.href;
            var shareUserId="";
            if(e.target.dataset.shareuserid){
                //shareuser="&shareuser="+e.dataset.shareuserid;
                $.cookie("shareUserId",e.target.dataset.shareuserid);
                shareUserId="&shareUserId="+$.cookie("shareUserId");
            }

            if(url&&url!="undefined"){
                //console.log(url);
                //console.log("跳转");
                if(/questiondetail/.test(url)){
                    location.href=url;
                }
                else{
                    location.href=url+shareUserId;
                }
            }
        }
    }
}
//发高额
function gotoheiexp(data){
    var eid=data.dataset.keyword;
    var e=arguments.callee.caller.arguments[0]||event;
    if(e&&e.stopPropagation()){
        e.stopPropagation();
    }else if(window.event){
        window.event.cancelBubble = true;
    }
    if(is_weixn()){
        $.cookie("expkeyword",eid);
        $.cookie("sendque","question");
        location.href="http://www.pulu.com/weixin/sendexpgpc.html";
    }
    else{
        location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+"&keyword="+eid+"&sendque=question";
    }
}
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
function datafun(d,ulid,num){
    //console.log(d);
    var fortime=0;//记录循环次数
    if(d.Message=="没有数据"||!d.Data||d.Data.length==0){
        num=1;
        readyover=0;
        console.log("没有数据了readyover："+readyover);
        queover=1;
        $("#waiting2").css("display","none");
        $("#nonews2").css("display","block");
    }else{
        for(var i= 0,r=d.Data.length;i<r;i++){
            fortime++;
            d.Data[i].index=i;
            if(d.Data[i].title&&d.Data[i].title.length>0){
                //匿名
                var unick="";
                if(d.Data[i].questionUserNick){
                    if(d.Data[i].ishidename==1){
                        unick="<a>匿名</a>";
                    }else{
                        unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].nick+"</a>";
                    }
                }
                //头像
                var uimgword="";
                if(d.Data[i].questionUserAva&&d.Data[i].ishidename!=1){
                    if(d.Data[i].ishidename==1){
                        uimgword="<a><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                    }else{
                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.Data[i].questionUserAva+"' onload='showloadimg(this)' style='display:none;'></a>";
                    }
                }else{
                    if(d.Data[i].ishidename==1){
                        uimgword="<a><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                    }else{
                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                    }
                };
                //有没有图片
                var haveimg="";
                if(d.Data[i].imgcount>0){
                    haveimg="<span class='isheighlogo haveimg'></span>";
                    //haveimg="(图)"
                }
                //是不是推荐
                var tuijianword="";
                var moneysty='style="position:absolute;right:0;"';
                if(d.Data[i].isStranger===1){
                    tuijianword="<div class='tuijian'></div>";
                    moneysty='style="position:absolute;right:64px;"';
                }
                var money="";//有没有钱
                if(d.Data[i].score>0){
                    var score= parseFloat(d.Data[i].score)/100;
                    money="<span class='havemy' "+moneysty+"> 悬赏 ¥ "+score+"</span>";
                }
                var tim="";
                if(d.Data[i].ctime){
                    tim=getDateDiff(getDateTimeStamp(d.Data[i].ctime));
                }
                var count=0;
                if(d.Data[i].count){
                    count=d.Data[i].count;
                }
                var caller="";
                //昵称
                var unick="";
                if(d.Data[i].questionUserNick){
                    if(d.Data[i].ishidename===1){
                        unick="<a>匿名</a>";
                    }else{
                        unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].questionUserNick+"</a>";
                    }
                }
                //结帖
                var answerword="";
                var overword="";
                if(d.Data[i].status.toString()=="0"){
                    answerword="";
                    overword="(已结帖)";
                    money="<span class='havemy' "+moneysty+"> ¥ "+score+"已分配</span>";
                }else{
                    var isinweixin="";
                    isinweixin="http://www.pulu.com/weixin/answerpage.html?";
                    //if(is_weixn()){
                    //    isinweixin="https://www.pulu.com/weixin/answerpage.html?";
                    //}else{
                    //    isinweixin="https://www.pulu.com/answerpage.html?id="+id+"&";
                    //}
                    if(d.Data[i].shareUserId&&d.Data[i].shareUserId.length>0){
                        answerword="<div class='ActionBar Question'> <div class='action_bar_inner'><div class='primary_item'><a class='WriteAnswer Button' onclick='hrefgo(this)' data-shareuserid='"+d.Data[i].shareUserId+"' data-page='"+ulid+"' data-href='"+isinweixin+"qid="+d.Data[i].id+"'>回答 </a></div> </div></div>";
                    }else{
                        answerword="<div class='ActionBar Question'> <div class='action_bar_inner'><div class='primary_item'><a class='WriteAnswer Button' onclick='hrefgo(this)' data-page='"+ulid+"' data-href='"+isinweixin+"qid="+d.Data[i].id+"'>回答 </a></div> </div></div>";
                    }

                }
                //问题转经验  回答数 付费数
                var tohrefurl="http://www.pulu.com/weixin/questiondetail.html?qid="+d.Data[i].id+"#fromuser="+id;
                var tranword="";
                var payoransw="回答 "+d.Data[i].answerCount;
                if(d.Data[i].ExpId&&d.Data[i].ExpId!=0){
                    tohrefurl="http://www.pulu.com/weixin/shareexppage.html?eid="+d.Data[i].ExpId+"#fromuser="+id;
                    tranword="(悬赏完成转经验)";
                    overword="";//结帖清除
                    payoransw="付费 "+d.Data[i].payCount;
                    money="<span class='havemy' "+moneysty+"> ¥ "+score+"</span>";
                }
                //地址
                var location="";
                if(d.Data[i].pululocation){
                    location="<div style='position:relative;' onclick='hrefgo(this)' data-page='"+ulid+"' data-href='"+tohrefurl+"'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:3px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                };
                //关键词
                var keywordnor;
                var keyword="<span class='keywordtit' style='display:none;'>关键词：</span>";
                if(d.Data[i].keywords){
                    keywordnor=d.Data[i].keywords.split(",");
                    for(var a=0;a<keywordnor.length;a++){
                        keyword+="<span>"+keywordnor[a]+"</span>";
                    }
                }
                //我也说说
                var gotoheiexp="<div class='gotoheiexp' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+">我也来说说：有关</div>";

                var tit=codetoface(d.Data[i].title);
                if(!d.Data[i].shareUserId){
                    if(!tim||/[a-z]/.test(tim)){
                        tim="刚刚";
                    }
                    $(ulid+" .addlistplace").append("<div class='pagedlist_item' onclick='hrefgo(this)' data-page='"+ulid+"' data-href='"+tohrefurl+"'><div class='feed_item feed_type_question'>"+tuijianword+"<div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+"</span> <div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2 onclick='hrefgo(this)' data-page='"+ulid+"' data-href='"+tohrefurl+"'><a class='question_link' onclick='hrefgo(this)' data-page='"+ulid+"' data-href='"+tohrefurl+"'>"+overword+tranword+tit+haveimg+"</a></h2>"+location+"<div class='ContentFooter QuestionFooter'>浏览 "+count+"&nbsp;&nbsp;&nbsp;"+payoransw+"</div>"+answerword+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+">"+"<div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div>");
                }
                else if(d.Data[i].shareUserId&&d.Data[i].shareUserId.length>0){
                    var des="";
                    if(d.Data[i].des){
                        des=codetoface(d.Data[i].des);
                    }
                    var sharetim="";
                    if(d.Data[i].shareTime){
                        sharetim=getDateDiff(getDateTimeStamp(d.Data[i].shareTime));
                    }
                    var location="";
                    if(d.Data[i].pululocation){
                        location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:3px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                    }
                    //转发调整金额样式
                    var moneysty='style="position:absolute;right:0;"';
                    if(d.Data[i].status.toString()=="0"){
                        answerword="";
                        overword="(已结帖)";
                        money="<span class='havemy' "+moneysty+"> ¥ "+score+"已分配</span>";
                    }
                    else{
                        money="<span class='havemy' "+moneysty+"> 悬赏 ¥ "+score+"</span>";
                    }
                    if(!sharetim||/[a-z]/.test(tim)){sharetim="刚刚"};
                    $("#quelist .addlistplace").append("<div class='pagedlist_item' onclick='hrefgo(this)' data-shareuserid='"+d.Data[i].shareUserId+"' data-page='"+ulid+"' data-href='"+tohrefurl+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+ d.Data[i].shareUserNick+"·转发</span>·"+sharetim+"</div><div class='info_wrapper' style='margin-left:10px;margin-top:7px;'> <div class='info'> <span class='feed_item_answer_user'>"+des+"</span> </div> </div> <div class='borderbox' data-shareuserid='"+d.Data[i].shareUserId+"' data-page='"+ulid+"' data-href='http://www.pulu.com/weixin/questiondetail.html?qid="+d.Data[i].id+"#fromuser="+id+"'><div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+"</span> <div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2><a class='question_link' onclick='hrefgo(this)' data-shareuserid='"+d.Data[i].shareUserId+"' data-page='"+ulid+"' data-href='"+tohrefurl+"'>"+overword+tranword+tit+haveimg+"</a></h2><div class='ActionBar Question'>"+location+"<div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>浏览 "+count+"&nbsp;&nbsp;&nbsp;"+payoransw+"</a> </div> <div class='action_item'> <a class='ReadMoreActionItem'></a> </div></div></div><div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+" >"+"<div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div></div>")
                }

            };
            //页面滚动判断
            if("#quelist"===$.cookie("pulupagepage")&&fortime===r&&$.cookie("pulupagescroll")&&parseFloat($.cookie("pulupagescroll"))>0){
                console.log("页面滚动："+$.cookie("pulupagescroll"));
                $(window).scrollTop(parseFloat($.cookie("pulupagescroll")));
                $.cookie("pulupagepage","");//清除页面ID
                $.cookie("pulupagescroll","");//当前滚动距离
                $.cookie("pulupagepage","");//当前显示页面
                $.cookie("tjcurrentIndex","");//推荐数据页码
                $.cookie("zhncurrentIndex","");//召唤你数据页码
                $.cookie("jycurrentIndex","");//经验 铺路数据页码
                $.cookie("quecurrentIndex","");//问题 铺路数据页码
            }
            if(fortime===r){
                readyover=0;
            }
        };
        num=0;
    }
};